#!/bin/bash

# 鱼C论坛闪拍监控 - Linux依赖安装脚本
# 作者: SOLO Coding
# 用途: 自动安装Python依赖包

set -e  # 遇到错误立即退出

echo "=== 鱼C论坛闪拍监控 - 依赖安装 ==="
echo "开始安装Python依赖包..."

# 检查Python是否安装
if ! command -v python3 &> /dev/null; then
    echo "错误: 未找到Python3，请先安装Python3"
    echo "Ubuntu/Debian: sudo apt update && sudo apt install python3 python3-pip"
    echo "CentOS/RHEL: sudo yum install python3 python3-pip"
    exit 1
fi

# 检查pip是否安装
if ! command -v pip3 &> /dev/null; then
    echo "错误: 未找到pip3，请先安装pip3"
    echo "Ubuntu/Debian: sudo apt install python3-pip"
    echo "CentOS/RHEL: sudo yum install python3-pip"
    exit 1
fi

echo "Python版本: $(python3 --version)"
echo "pip版本: $(pip3 --version)"
echo ""

# 升级pip
echo "升级pip..."
python3 -m pip install --upgrade pip

# 安装依赖
echo "安装项目依赖..."
if [ -f "requirements.txt" ]; then
    python3 -m pip install -r requirements.txt
    echo "✅ 依赖安装完成！"
else
    echo "未找到requirements.txt，手动安装依赖..."
    python3 -m pip install requests beautifulsoup4 lxml schedule
    echo "✅ 依赖安装完成！"
fi

echo ""
echo "=== 安装完成 ==="
echo "现在可以运行监控脚本了："
echo "  ./start_monitor.sh          # 前台运行"
echo "  ./start_scheduled_monitor.sh # 定时调度模式"
echo "  ./run_background.sh         # 后台运行"
echo ""